package com.jy.wms.controller;

import com.github.pagehelper.Page;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.UUIDUtils;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.WmsSoCustom;
import com.jy.wms.service.WmsSoCustomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @ClassName: WmsSoCustomController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author Jane
 * @Date Fri Dec 29 17:10:16 CST 2017
 */
@Controller
@RequestMapping("/wmssocustom")
@Api(value = "/wmssocustom", description = "采购订单附加表")
public class  WmsSoCustomController extends BaseController<WmsSoCustomService,WmsSoCustom> {

    @PostMapping(value = "list")
    @ApiOperation(value = "查询信息",response = JSONObject.class, notes = "查询信息")
    public @ResponseBody
    ResultPage<WmsSoCustom> getWmsSoCustom(@RequestBody WmsSoCustom entity, HttpSession session) {
        Page<WmsSoCustom> list= baseService.baseSelectPage(entity);
            return renderPage(list);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除信息",response = JSONObject.class, notes = "删除信息")
    public @ResponseBody
    JsonResult deleteWmsSoCustom(@RequestBody List<String> ids) {
        Integer flag=baseService.baseDeleteBathPrimaryKeys(ids);
        return renderSuccess("删除成功");
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增采购订单附加表信息",response = JSONObject.class, notes = "新增采购订单附加表信息")
    public @ResponseBody JSONObject addWmsSoCustom(@RequestBody WmsSoCustom entity) {
        try{
            entity.setId(UUIDUtils.uuid());
            baseService.baseInsert(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(),"新增采购订单附加表信息成功","",  JSONObject.fromObject(entity).toString());
        }catch (ServiceException e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "新增采购订单附加表信息失败", e.getMessage(), "");
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "新增采购订单附加表信息失败", e.getMessage(), "");
        }
    }

    @GetMapping(value = "getWmsSoCustom/{ssfydid}")
    @ApiOperation(value = "查看单个信息",response = JSONObject.class, notes = "GET查看单个信息")
    public @ResponseBody JSONObject getWmsSoCustomById(@PathVariable("ssfydid") String ssfydid) {
        WmsSoCustom entity=baseService.baseSelectByPrimaryKey(ssfydid);
        return JSONObject.fromObject(entity);
    }
    @PostMapping(value = "edit")
    @ApiOperation(value = "编辑采购订单附加表信息",response = JSONObject.class, notes = "编辑采购订单附加表信息")
    public @ResponseBody JSONObject editWmsSoCustom(@RequestBody WmsSoCustom entity) {
        try{
            baseService.baseUpdateByPrimaryKeySelective(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(),"编辑采购订单附加表信息成功","",  JSONObject.fromObject(entity).toString());
        }catch (ServiceException e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "编辑采购订单附加表信息失败", e.getMessage(), "");
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "编辑采购订单附加表信息失败", e.getMessage(), "");
        }
    }
}
